package keeto.com.vn.classfied.model;

import keeto.com.vn.classified.core.ClassifiedCore;
import keeto.com.vn.classified.core.ClassifiedListener;
import keeto.com.vn.classified.core.MockRunnable;

public class Command implements Comparable<Command> {

	public static final int DEFAULT_RETRY_TIMES = 3;
	public MockRunnable runnable;
	public ClassifiedListener listener;
	public String action;
	int priority = ClassifiedCore.PRIORITY_MEDIUM;// default = 5;1-5
	int sequence = ClassifiedCore.sequencing.getAndIncrement(); // ++sequence
	long time = System.currentTimeMillis();
	public int retryTime = DEFAULT_RETRY_TIMES;
	public boolean sendByUI = false;

	public Command(MockRunnable runnable, ClassifiedListener listener, String action,
			int priority, boolean sendByUI) {
		this.runnable = runnable;
		this.listener = listener;
		this.action = action;
		this.priority = priority;
		this.sendByUI = sendByUI;
	}

	@Override
	public int compareTo(Command another) {
		int result = priority - another.priority;
		if (result == 0) {
			result = (int) (time - another.time);
		}
		return result;
	}

}
